//-----------------------------------------------------------------------
// <copyright file="a_CacheStaticMenuCatDAOBase.cs" company="AACECOM">
//     Copyright (c) AACECOM. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------

using System;
using System.Data;
using System.Data.Common;
using System.Collections;
using Microsoft.Practices.EnterpriseLibrary.Data;
using ThoiTrang.Entities;

namespace ThoiTrang.Data
{    
    public abstract class a_CacheStaticMenuCatDAOBase
    {
        #region Common methods
        public virtual a_CacheStaticMenuCat Createa_CacheStaticMenuCatFromReader(IDataReader reader)
        {
            a_CacheStaticMenuCat item = new a_CacheStaticMenuCat();
            try
            {
                if (!reader.IsDBNull(reader.GetOrdinal("MID"))) item.MID = (int)reader["MID"];
                if (!reader.IsDBNull(reader.GetOrdinal("CatID"))) item.CatID = (int)reader["CatID"];
                if (!reader.IsDBNull(reader.GetOrdinal("CatName"))) item.CatName = (string)reader["CatName"];
                if (!reader.IsDBNull(reader.GetOrdinal("StoreID"))) item.StoreID = (int)reader["StoreID"];
                if (!reader.IsDBNull(reader.GetOrdinal("DomainID"))) item.DomainID = (int)reader["DomainID"];
            }
            catch (Exception ex)
            {                
                throw ex;
            }
            return item;
        }
        #endregion
        
        #region Createa_CacheStaticMenuCat methods
            
        public virtual void Createa_CacheStaticMenuCat(a_CacheStaticMenuCat a_CacheStaticMenuCat)
        {
            try
            {
                Database database = DatabaseFactory.CreateDatabase();
                DbCommand dbCommand = database.GetStoredProcCommand("a_CacheStaticMenuCats_ins");
                
                database.AddInParameter(dbCommand, "@CatID", DbType.Int32, a_CacheStaticMenuCat.CatID);
                database.AddInParameter(dbCommand, "@CatName", DbType.String, a_CacheStaticMenuCat.CatName);
                database.AddInParameter(dbCommand, "@StoreID", DbType.Int32, a_CacheStaticMenuCat.StoreID);
                database.AddInParameter(dbCommand, "@DomainID", DbType.Int32, a_CacheStaticMenuCat.DomainID);
                database.AddOutParameter(dbCommand, "@MID", DbType.Int32, 0);
                
                database.ExecuteNonQuery(dbCommand);
                a_CacheStaticMenuCat.MID = (int)database.GetParameterValue(dbCommand, "@MID");
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        #endregion

        #region Updatea_CacheStaticMenuCat methods
        
        public virtual void Updatea_CacheStaticMenuCat(a_CacheStaticMenuCat a_CacheStaticMenuCat)
        {
            try
            {
                Database database = DatabaseFactory.CreateDatabase();
                DbCommand dbCommand = database.GetStoredProcCommand("a_CacheStaticMenuCats_upd");            
                
                database.AddInParameter(dbCommand, "@MID", DbType.Int32, a_CacheStaticMenuCat.MID);
                database.AddInParameter(dbCommand, "@CatID", DbType.Int32, a_CacheStaticMenuCat.CatID);
                database.AddInParameter(dbCommand, "@CatName", DbType.String, a_CacheStaticMenuCat.CatName);
                database.AddInParameter(dbCommand, "@StoreID", DbType.Int32, a_CacheStaticMenuCat.StoreID);
                database.AddInParameter(dbCommand, "@DomainID", DbType.Int32, a_CacheStaticMenuCat.DomainID);
                
                database.ExecuteNonQuery(dbCommand);
            }
            catch (Exception ex)
            {
               throw ex;
            }
        }
        
        #endregion

        #region Deletea_CacheStaticMenuCat methods
        public virtual void Deletea_CacheStaticMenuCat(int mid)
        {
            try
            {
                Database database = DatabaseFactory.CreateDatabase();
                DbCommand dbCommand = database.GetStoredProcCommand("a_CacheStaticMenuCats_del");
                
                database.AddInParameter(dbCommand, "@MID", DbType.Int32, mid);
                
                database.ExecuteNonQuery(dbCommand);
            }
            catch (Exception ex)
            {
               throw ex;
            }
        }

        #endregion

        #region Geta_CacheStaticMenuCat methods
        
        public virtual a_CacheStaticMenuCat Geta_CacheStaticMenuCat(int mid)
        {            
            try
            {
                Database database = DatabaseFactory.CreateDatabase();
                DbCommand dbCommand = database.GetStoredProcCommand("a_CacheStaticMenuCats_sel");
                
                database.AddInParameter(dbCommand, "@MID", DbType.Int32, mid);
                
                a_CacheStaticMenuCat a_CacheStaticMenuCat =  null;
                using (IDataReader reader = database.ExecuteReader(dbCommand))
                {
                    if (reader.Read())
                    {
                        a_CacheStaticMenuCat = Createa_CacheStaticMenuCatFromReader(reader);
                        reader.Close();
                    }
                }
                return a_CacheStaticMenuCat;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        
        #endregion

        #region Geta_CacheStaticMenuCatList methods
        public virtual a_CacheStaticMenuCatCollection Geta_CacheStaticMenuCatList(a_CacheStaticMenuCatColumns orderBy, OrderDirection orderDirection, int page, int pageSize, out int totalRecords)
        {            
            try
            {
                Database database = DatabaseFactory.CreateDatabase();
                DbCommand dbCommand = database.GetStoredProcCommand("a_CacheStaticMenuCats_selList");
                
                database.AddInParameter(dbCommand, "@OrderBy", DbType.AnsiString, orderBy.ToString());
                database.AddInParameter(dbCommand, "@OrderDirection", DbType.AnsiString, orderDirection.ToString());
                database.AddInParameter(dbCommand, "@Page", DbType.Int32, page);
                database.AddInParameter(dbCommand, "@PageSize", DbType.Int32, pageSize);
                database.AddOutParameter(dbCommand, "@TotalRecords", DbType.Int32, 4);
                
                a_CacheStaticMenuCatCollection a_CacheStaticMenuCatCollection = new a_CacheStaticMenuCatCollection();
                using (IDataReader reader = database.ExecuteReader(dbCommand))
                {
                    while (reader.Read())
                    {
                        a_CacheStaticMenuCat a_CacheStaticMenuCat = Createa_CacheStaticMenuCatFromReader(reader);
                        a_CacheStaticMenuCatCollection.Add(a_CacheStaticMenuCat);
                    }
                    reader.Close();
                }
                totalRecords = (int)database.GetParameterValue(dbCommand, "@TotalRecords");
                return a_CacheStaticMenuCatCollection;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        
        public virtual a_CacheStaticMenuCatCollection Geta_CacheStaticMenuCatList(a_CacheStaticMenuCatColumns orderBy, OrderDirection orderDirection)
        {            
            int totalRecords = 0;
            return Geta_CacheStaticMenuCatList(orderBy, orderDirection, 0, 0, out totalRecords);
        }
        
        #endregion
    }
}